<template>
  <div class="logincontainer">
    <el-form ref="loginFormRef" label-width="80px" class="loginForm" :model="loginModel" :rules="rules" :inline="false">
      <el-form-item>
        <div class="loginTitle">系统登录</div>
      </el-form-item>
      <el-form-item prop="username" label="账户">
        <el-input v-model="loginModel.username" size="large" placeholder="请输入账户"></el-input>
      </el-form-item>
      <el-form-item prop="password" label="密码">
        <el-input v-model="loginModel.password" size="large" type="password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item prop="code" label="验证码">
        <el-row>
          <el-col :span="16" style="padding-right: 10px; padding-left: 0px">
            <el-input v-model="loginModel.code" size="large" placeholder="请输入验证码"></el-input>
          </el-col>
          <el-col :span="8" style="padding-right: 0px; padding-left: 10px">
            <!-- <el-input placeholder="请输入验证码" v-model="loginModel.code"></el-input> -->
            <img :src="imgSrc" class="image" @click="getImage" />
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item>
        <el-row>
          <el-col :span="12" style="padding-right: 10px; padding-left: 0px">
            <el-button class="mybtn" type="primary" size="large" @click="handleLogin(loginFormRef)">登录</el-button>
          </el-col>
          <el-col :span="12" style="padding-right: 0px; padding-left: 10px">
            <el-button class="mybtn" type="large" size="default">取消</el-button>
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup lang="ts">
import useImage from './composables/useImage'
import useBaseLogin from './composables/useBaseLogin'
import { useLogin } from './composables/useLogin'
import { useRouter } from 'vue-router'
// 在 setup 函数中获取 router 对象
const router = useRouter()
//基础数据
const { loginModel, rules, loginFormRef } = useBaseLogin()
// 获取验证码
const { imgSrc, getImage } = useImage()
//登录
const handleLogin = (loginFormRef: any) => useLogin(router, loginFormRef, loginModel)
</script>
<style scoped lang="scss">
.logincontainer {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;

  .loginForm {
    height: 320px;
    width: 400px;
    border-radius: 10px;
    padding: 20px 35px;
    box-shadow: 0 0 25px #cac6c6;

    .loginTitle {
      width: 100%;
      font-size: 24px;
      font-weight: 600;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .image {
      height: 40px;
      width: 100%;
    }

    .mybtn {
      width: 100%;
    }
  }
}

:deep(.el-row) {
  width: 100% !important;
}
</style>
